<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/common.js"></script>
</head>
<body>
	账号：<input type="text" id="login_id" placeholder="请输入账号"><br>
	密码：<input type="password" id="login_password" placeholder="请输入密码"><br>
	<input type="button" value="登陆"  onclick="login()"><br>
	<input type="button" value="测试ajax默认参数" onclick="testSetUp()"><br>
	<input type="button" value="清初localStorage缓存"  onclick="clearStorage()">
	<img alt="X" src="image/electroicMapIcon.png">
</body>
<script type="text/javascript">
	function testSetUp(){
		$.ajax({
			type : 'post',
        	url : 'http://localhost:9001/test/hello',
        	success : function(data){
        		console.log("data",data);
        	}
		})
	}
	
	function login(){
		var login_id = $('#login_id').val();
		var login_password = $('#login_password').val();
		
		if(null==login_id||''==login_id){
			alert("请输入账号");
			return;
		}
		if(null==login_password||''==login_password){
			alert("请输入密码");
			return;
		}
		$.ajax({
			type : 'post',
        	url : 'http://localhost:9001/auth/login/logon',
        	contentType : 'application/json;charset=utf-8',
        	data : JSON.stringify({
        		login_id : login_id
        		,login_password : login_password
        	}),
        	success : function(data){
        		if(200==data.code){
        			console.log("token",data.data);
        			sessionStorage.setItem("token",data.data);
	        		console.log('把token放入浏览器缓存');
        			alert(data.msg);
        			window.location.reload();
        			return;
        		}
        		alert(data.msg);
        	}
		})
	}
	
	function clearStorage(){
		localStorage.removeItem("token");
		console.log("清除token属性");
		console.log("token",localStorage.getItem("token"));
		window.location.reload();
	}
</script>
</html>